﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SimCMS.Model;
using SimCMS.Repository;

namespace SimCMS.Manager
{

    public class SimadminManager : ISimadminManager
    {
        public IRepository<Simadmin> SimadminRepository { get; set; }

        public object Save(Simadmin entity)
        {
            return this.SimadminRepository.Save(entity);
        }

        public void Delete(object id)
        {
            this.SimadminRepository.Delete(this.Get(id));
        }

        public Simadmin Get(object id)
        {
            return this.SimadminRepository.Get(id);
        }

        public IList<Simadmin> LoadAll()
        {
            return this.SimadminRepository.LoadAll();
        }

        public void Update(Simadmin entity)
        {
            this.SimadminRepository.Update(entity);
        }

        public bool Login(Simadmin model)
        {
            String[] Names = new String[] { "UserName", "Password" };
            String[] values = new String[] { model.UserName,model.Password};
            var LoginUser = this.SimadminRepository.FindByNamedQuery("Login", Names, values);
            if (LoginUser.Count > 0)
            {
                return true;
            }
            else
            {
                this.SimadminRepository.Save(new Simadmin { UserName = "admin", Password = "123" });
                return false;
            }
        }
    }
}
